package io.renren.utils;

import org.quartz.Scheduler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ShutdownQuartz implements ServletContextListener {

    private Logger logger = LoggerFactory.getLogger(getClass());


    public void contextDestroyed(ServletContextEvent arg0) {
        try {
            // Get a reference to the Scheduler and shut it down
            logger.warn("--关闭 scheduler----");
            Scheduler scheduler = (Scheduler) SpringContextUtils.getBean("scheduler");
            scheduler.shutdown(true);
            // Sleep for a bit so that we don't get any errors
            Thread.sleep(1000);
        } catch (Exception e){
            logger.error("--shut down scheduler error",e);
        }
    }
    public void contextInitialized(ServletContextEvent arg0) {
    }
}